#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
using namespace std;
int a[] = { 1,-1,0,0 };
int b[] = { 0,0,1,-1 };
class Solution {
public:
    vector<vector<int>> flipChess(vector<vector<int> >& A, vector<vector<int> >& f)
    {
        vector<vector<int>> ret = A;
        for (int i = 0;i < f.size();i++)
        {
            for (int j = 0;j < 4;j++)
            {
                int x = f[i][0] - 1 + a[j];
                int y = f[i][1] - 1 + b[j];
                if ((x >= 0 && x < ret.size()) && (y >= 0 && y <= ret[0].size()))
                {
                    ret[x][y] = ret[x][y] == 1 ? 0 : 1;
                }
            }
        }
        return ret;
    }
};